package com.yz.group1.group_1.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yz.group1.group_1.entity.UserAccount;
import com.yz.group1.group_1.mapper.UserAccountMapper;
import com.yz.group1.group_1.service.UserAccountService;
import org.springframework.stereotype.Service;
import java.util.Date;

@Service
public class UserAccountServiceImpl extends ServiceImpl<UserAccountMapper, UserAccount> implements UserAccountService {

    @Override
    public boolean login(String username, String password) {
        QueryWrapper<UserAccount> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username).eq("password", password);
        return baseMapper.selectCount(queryWrapper) > 0;
    }

    @Override
    public boolean register(UserAccount userAccount) {
        userAccount.setCreatedAt(new Date().toString());
        userAccount.setUpdatedAt(new Date().toString());
        userAccount.setUserType(3); // 患者类型
        return save(userAccount);
    }

    @Override
    public UserAccount getByUsername(String username) {
        QueryWrapper<UserAccount> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        return baseMapper.selectOne(queryWrapper);
    }
}